package com.tao.util.pack.send.impl;

import org.json.JSONException;

import com.tao.domain.User;
import com.tao.util.BaseRequest;
import com.tao.util.HttpUtil;
import com.tao.util.UrlConf;
import com.tao.util.Utils;
import com.tao.util.pack.Msg;
import com.tao.util.pack.send.GroupMessage;
import com.tao.util.pack.send.util.SendFileUtils;
import com.tao.util.pack.send.util.SendImagesUtils;


public class GroupMessageInterImpl implements GroupMessage {
    
	/**
	 * 发送文本信息
	 */
	@Override
	public String sendGroupMsg(User user,Msg msg) {
		// TODO Auto-generated method stub
		 //String stringEntity = new JGonUtil().toGsonString(map);
		Long currentTimeMillis = System.currentTimeMillis();
		 String stringEntity = "{\"Msg\":{\"ClientMsgId\":\""+currentTimeMillis+"\",\"Content\":\""+msg.getContent()+"\",\"FromUserName\":\""+user.getUserName()+"\",\"LocalID\":\""+currentTimeMillis+"\",\"ToUserName\":\""+msg.getToUserName()+"\",\"Type\":1},\"BaseRequest\":{\"DeviceID\":\""+Utils.getDeviceID()+"\",\"Sid\":\""+user.getSid()+"\",\"Skey\":\""+user.getSkey()+"\",\"Uin\":\""+user.getUin()+"\"}}";

	       String str = new HttpUtil().sendPost(UrlConf.webwxSendMsg +"&pass_ticket="+ user.getPass_ticket(), user.getCookie(), stringEntity);
	       return str;
	}
	/**
	 * 发送图片信息
	 */
	@Override
	public String sendGroupImageMsg(String filePath,User user,Msg msg) {
	     
		String result  = null;
		try {
			 result  = new SendImagesUtils().send( filePath, user, msg);
			return	result;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			System.out.println("JSONException");
			return result;
		}
	}
	/**
	 * 发送文件信息
	 */
	@Override
	public String sendGroupFileMsg(String filePath,String fileName,User user,BaseRequest bRequest,Msg msg) {
		
		try {
			      
			return	new SendFileUtils().send( filePath, fileName, user, bRequest, msg);
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			System.out.println("JSONException");
		}
		return fileName;
	}

}
